package com.iptv.grape.jss.mgr;

import java.util.HashMap;
import java.util.Map;

public class UrlMgr {
//    String url ="http://172.30.13.66:8888/";
    /***
     * 拼接URL
     * @param url
     * @param params
     * @return
     */
    public static String toUrl(String url, Map<String,Object> params){
        if(params==null&&params.size()<1)
            return url;
        StringBuilder stringBuilder = new StringBuilder(url);
            int i = 0;
            for(Map.Entry<String,Object> entry:params.entrySet()) {
                if(i==0) {
                    if (stringBuilder.indexOf("?") < 1)
                        stringBuilder.append("?").append(entry.getKey()).append("=").append(entry.getValue());
                    else if(stringBuilder.indexOf("&")< stringBuilder.length()-1){
                        stringBuilder.append("&").append(entry.getKey()).append("=").append(entry.getValue());
                    } else
                        stringBuilder.append(entry.getKey()).append("=").append(entry.getValue());
                }else
                    stringBuilder.append("&").append(entry.getKey()).append("=").append(entry.getValue());
                i=i+1;
            }
        return  stringBuilder.toString();

    }
    public static String webUrl(String url){
        Map<String,Object> map = new HashMap<>();
        map.put("UserId","dxrmcs");
        map.put("UserToken","dxrmcs");
        map.put("PlatForm","zx");
        return toUrl(url,map);
    }


}
